#!/usr/bin/env python
import os
from app import create_app, db
from app.models import User
from werkzeug.security import generate_password_hash
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand

app = create_app('default')
#app = create_app(os.getenv('FLASK_CONFIG') or 'default')

migrate = Migrate(app, db)

def make_shell_context():
	return dict(app=app, db=db, User=User)
	#return dict(app=app, db=db, User=User, Role=Role)

manager = Manager(app)
manager.add_command("shell", Shell(make_context=make_shell_context)) #the context define by Python shell
manager.add_command('db', MigrateCommand)

@manager.command
def add_user():
    #user = User(username='wangsz',password_hash=generate_password_hash('wangsz2018'))
    user = User(username='admin',password_hash=generate_password_hash('admin'))
    db.session.add(user)
    db.session.commit()

if __name__ == '__main__':
	manager.run()
